package wangjg.xuexiban.activity.category;

import java.net.URISyntaxException;
import java.util.List;

import wangjg.xuexiban.R;
import wangjg.xuexiban.entity.Category;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ListAdapter;

public class CategoryGridActivity extends BasicCategoryActivity {
	private ListAdapter adapter;
	
	public CategoryGridActivity() throws URISyntaxException {
		Log.i("CategoryGridActivity", "CategoryGridActivity()");
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.category_grid);
		this.loadCategoryList();
	}
	
	protected void onStart() {
		super.onStart();
	}
	
	@Override
	protected void initContentView() {
		if(adapter==null){
			GridView gridView = (GridView) findViewById(R.id.myGrid);
			ListAdapter adapter = new MyAdapter();
			gridView.setAdapter(adapter);
		}
	}

    public class MyAdapter extends BaseAdapter {
    	
        public MyAdapter() {
        }

        public View getView(int position, View convertView, ViewGroup parent) {
        	Category category = getCategoryList().get(position);
        	View view = CategoryGridActivity.this.getCategoryView(category);
            return view;
        }

        public final int getCount() {
        	List<Category> list = getCategoryList();
        	if(list==null){
        		return 0;
        	}
            return getCategoryList().size();
        }

        public final Object getItem(int position) {
            return position;
        }

        public final long getItemId(int position) {
            return position;
        }
    }
}
